package com.app.micaihu.view.army.activity

import android.os.Bundle
import androidx.recyclerview.widget.GridLayoutManager
import com.app.base.BaseMvpActivity
import com.app.http.bean.BaseBean
import com.app.micaihu.R
import com.app.micaihu.configure.Config
import com.app.micaihu.view.army.adapter.ArmyMedalListAdapter
import com.app.micaihu.view.army.contract.ArmyHonourContract
import com.app.micaihu.view.army.header.ArmyMedalHeader
import com.app.micaihu.view.army.presenter.ArmyHonourPresenter
import com.app.micaihu.view.bean.ArmyHonour
import com.blankj.utilcode.util.ToastUtils
import kotlinx.android.synthetic.main.army_medal_list_activity.*

/**
 * 军团勋章列表
 */
class ArmyMedalListActivity : BaseMvpActivity<ArmyHonourContract.View, ArmyHonourPresenter>(), ArmyHonourContract.View {

    override fun getLayoutId() = R.layout.army_medal_list_activity


    override fun getPresenter() = ArmyHonourPresenter()

    override fun getBundle(bundle: Bundle) {
        toUid = bundle.getString(Config.Extra.toUid, "")
    }

    var toUid = ""

    private val armyUserHonourAdapter: ArmyMedalListAdapter by lazy {
        val armyUserHonourAdapter = ArmyMedalListAdapter()
        rvUserHonour.layoutManager = GridLayoutManager(thisContext, 3)

        armyUserHonourAdapter
    }
    private val armyHonourAdapter: ArmyMedalListAdapter by lazy {
        val armyHonourAdapter = ArmyMedalListAdapter()
        rvArmyHonour.layoutManager = GridLayoutManager(thisContext, 3)

        armyHonourAdapter
    }

    private val armyActivityHonorAdapter: ArmyMedalListAdapter by lazy {
        val armyActivityHonorAdapter = ArmyMedalListAdapter()
        rvActivityHonour.layoutManager = GridLayoutManager(thisContext, 3)

        armyActivityHonorAdapter
    }

    private val armyHonourHeader: ArmyMedalHeader by lazy {
        ArmyMedalHeader(thisContext)
    }

    override fun setData() {
        rvArmyHonour.adapter = armyHonourAdapter
        rvActivityHonour.adapter = armyActivityHonorAdapter
        rvUserHonour.adapter = armyUserHonourAdapter
        mPresenter?.honour(toUid)
        rlHeader.addView(armyHonourHeader)
    }

    override fun addListeners() {
        armyUserHonourAdapter.setOnItemClickListener { adapter, view, position ->
            ToastUtils.showShort("后续版本开放")
        }
        armyHonourAdapter.setOnItemClickListener { adapter, view, position ->
            ToastUtils.showShort("加入军团即可获得勋章")
        }
        armyActivityHonorAdapter.setOnItemClickListener { adapter, view, position ->
            ToastUtils.showShort("加入军团即可获得勋章")
        }

    }

    override fun handleHonour(result: BaseBean<ArmyHonour?>?) {
        if (result == null) {
//            armyMedalListAdapter.setEmptyView(errorView)
        } else {
            if (result.isSuccess()) {
                result.data?.let { data ->
                    data.userInfo?.let {
                        armyHonourHeader.setUserData(it)
                    }
                    armyUserHonourAdapter.setList(data.userHonour)
                    armyHonourAdapter.setList(data.armyHonour)
                    armyActivityHonorAdapter.setList(data.activityHonour)

                    tvUserHonourNum.text = data.userHonourNum
                    tvArmyHonourNum.text = data.armyHonourNum
                    tvActivityHonourNum.text = data.activityNum
                }
            } else {
                ToastUtils.showShort(result.msg)
            }
        }
    }


}